/**
 * 2015-12-22
 * CourseServiceImpl.java
 * author:sherlochao
 */
package com.sherlochao.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.sherlochao.beans.CourseBean;
import com.sherlochao.dao.CourseDao;
import com.sherlochao.model.Course;
import com.sherlochao.model.Student;
import com.sherlochao.model.StudyCourse;
import com.sherlochao.model.Teacher;
import com.sherlochao.service.CourseService;

/**
 * @author yinchao
 *
 */
@Transactional
@Service("courseService")
public class CourseServiceImpl implements CourseService{
	
	@Resource
	private CourseDao courseDao;

	@Override
	public Course get(String courseId) {
		// TODO Auto-generated method stub
		return courseDao.get(courseId);
	}

	@Override
	public List<StudyCourse> listStudyCourseByCourseId(String courseId) {
		// TODO Auto-generated method stub
		return courseDao.listStudyCourseByCourseId(courseId);
	}

	@Override
	public List<Student> listStudentByCourseId(String courseId) {
		// TODO Auto-generated method stub
		return courseDao.listStudentByCourseId(courseId);
	}

	@Resource
	private CourseService courseService;
	
	@Override
	public String test(String courseId) {
		CourseBean courseBean = new CourseBean();
		Course course = courseService.get(courseId);
		courseBean.setCourseId(course.getCourseNumber());
		courseBean.setCourseName(course.getCourseName());
		List<StudyCourse> studyCourses = courseService.listStudyCourseByCourseId(courseId);
		courseBean.setScores(studyCourses);
		courseBean.setCount(studyCourses.size());
		List<Student> students = courseService.listStudentByCourseId(courseId);
		courseBean.setStudentNames(students);
		List<Teacher> teachers = courseService.listTeacherByCourseId(courseId);
		courseBean.setTeacherNames(teachers);
		
		String json = JSON.toJSONString(courseBean);
		return json;
	}

	@Override
	public List<Teacher> listTeacherByCourseId(String courseId) {
		// TODO Auto-generated method stub
		return courseDao.listTeacherByCourseId(courseId);
	}

}
